package top.stmo.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 *         Jedis连接池
 */
public class JedisConnectionFactory {

    private static final JedisPool jedisPool;

    static {
        //配置连接池
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        //配置最大连接数
        poolConfig.setMaxTotal(8);
        //配置最大空闲连接
        poolConfig.setMaxIdle(5);
        //配置最小空闲连接
        poolConfig.setMinIdle(2);
        //配置等待时长
        poolConfig.setMaxWaitMillis(1000);
        //创建连接池对象
        jedisPool = new JedisPool(poolConfig,"localhost",6379,1000);
    }

    public static Jedis getJedis() {
        return jedisPool.getResource();
    }
}
